package mastermind.gui;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/**
 * 
 * Custom cell renderer for the peg table
 *
 */

public class CustomCellRendererPegs extends DefaultTableCellRenderer  {

    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
    {
        Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        
        if(value instanceof String) //colour peg cells depending on their contents
        {
        	if(value.equals("B"))
        	{
                c.setBackground(Color.black);
        	}
        	if(value.equals("W"))
        	{
                c.setBackground(Color.white);
        	}
        	if(value.equals("  X"))
        	{
        		c.setBackground(Color.gray);
        	}
        }
        return c;
    }
}
